package com.study.shiro;


import com.study.dbo.ManagerDO;
import com.study.service.ManagerService;
import org.apache.shiro.authc.AuthenticationInfo;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.authc.credential.SimpleCredentialsMatcher;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;


/**
 * 
 * @author chenjie 
 * 密码比较器
 *
 */
public class CustomCredentialsMatcher extends SimpleCredentialsMatcher {

	@Autowired
	@Qualifier("managerService")
	private ManagerService managerService;

	//密码比较的方法   token代表用户在界面输入的用户名和密码     info代表从数据库中得到加密数据
	@Override
	public boolean doCredentialsMatch(AuthenticationToken token, AuthenticationInfo info) {
		//1.向下转型
		System.out.println("Sss");
		UsernamePasswordToken upToken = (UsernamePasswordToken) token;
		ManagerDO managerDO = managerService.findByAccount(((UsernamePasswordToken) token).getUsername());
		if (managerDO == null) {
			return false;
		}
		Object dbPwd = info.getCredentials();
		return this.equals(managerDO.getManagerPasswd(), upToken.getPassword());
	}

	
}
